package com.ccit.employee.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ccit.common.client.UserClient;
import com.ccit.common.result.Result;
import com.ccit.employee.mapper.EmployeeMapper;
import com.ccit.employee.service.EmployeeService;
import com.ccit.model.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
    @Autowired
    private UserClient userClient;
    @Autowired
    private EmployeeMapper employeeMapper;

    public boolean removeAdminByName(String name) {
        Result result = userClient.removeAdminById(name);
        String flag = result.getMessage();
        if (flag.equals("成功")) {
            //当删除调用成功时
            return true;
        } else {
            return false;
        }
    }

    @Override
    public List<Employee> getCoachByPage() {
        QueryWrapper<Employee> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type", "教练");
//        mybatis-plus构造查询条件，查询type为教练的employee
        List<Employee> list = employeeMapper.selectList(queryWrapper);
        if (!list.isEmpty()) {
            return list;
        }
        return Collections.emptyList();
    }

}
